<?php
//
// test HTTP POST submitter, using libcurl
//
include_once "config.php";


$value = 'something from somewhere';





// the target url which contains scripts that accepts post request
$login = $api_auth."?source=".$source;

$confidential  = array('username' => "delacour", 'password' => "wacy1314");
// we are spoofing Yahoo Seeker bot >:)
$useragent= $_SERVER['HTTP_USER_AGENT'];

$result = curl_post($login, $confidential);

$json = json_decode($result);

$code = $json -> {'code'};

if ($code && !empty($code)){

}
else{
	if ( $json -> {'username'} && $json -> {'id'} && $json -> {'auth'}){
		setcookie($th_username, $json -> {'username'}, time()+360000); 
		setcookie($th_id, $json -> {'id'}, time()+360000);
		setcookie($th_auth, $json -> {'auth'}, time()+360000);
	}
	
}


$auth = array ( 'auth' => ($json -> {'auth'}) );
$username = $json -> {'username'};

$progress = 'http://api.bgm.tv/user/'.$username.'/progress?subject_id=10377&source='.$source;

$result = curl_post($progress, $auth);

print $result;


function curl_post($url, array $post = NULL, array $options = array()) 
{ 
    $defaults = array( 
        CURLOPT_POST => 1, 
        CURLOPT_HEADER => 0, 
        CURLOPT_URL => $url, 
        CURLOPT_FRESH_CONNECT => 1, 
        CURLOPT_RETURNTRANSFER => 1, 
        CURLOPT_FORBID_REUSE => 1, 
        CURLOPT_TIMEOUT => 4, 
        CURLOPT_POSTFIELDS => http_build_query($post) 
    ); 

    $ch = curl_init(); 
    curl_setopt_array($ch, ($options + $defaults)); 
    if( ! $result = curl_exec($ch)) 
    { 
        trigger_error(curl_error($ch)); 
    } 
    curl_close($ch); 
    return $result; 
} 


?>